﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Import Namespace="Tencent.OA.ACM.Entity" %>
<%@ Import Namespace="Tencent.OA.ACM.App" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>ViewPhoto</title>
       <link href="<%= this.Url.Content("~/content/Global.css") %>" rel="Stylesheet" type="text/css" />
    <link href="<%= this.Url.Content("~/content/Site.css") %>" rel="Stylesheet" type="text/css" />
    <script type="text/javascript" language="javascript" src="<%=this.Url.Content("~/content/scripts/jquery-1.4.2.js") %>"></script>

   <%-- <script src="<%=this.Url.Content("~/content/Scripts/jquery.form.js")%>" type="text/javascript"></script>--%>    
</head>
<body style="width: 675px;" frame-border=0px;>
 
<% using (Html.BeginForm("ViewPhoto","Route",FormMethod.Post,new {enctype="multipart/form-data"}))
   {%>
   
      <%=this.Html.Hidden("stationID", ViewData["stationID"])%>
    <div id="photoView">
        <%--<iframe frameborder="0">--%>
          
            
        <div id="dv_photo_frame" class="dv_photo_frame">
            <%
                if (ViewData["sationImg"] != null)
                {
                    IList<Attachment> list = ViewData["sationImg"] as IList<Attachment>;
                    if (list != null && list.Count>0)
                    {
                        foreach (Attachment item in list)
                        {
                                        %>
                                        <div class="attatch_img_item">
                                        <div class="dv_photo_del" title="点击删除" onclick="delImg('<%=item.AttachmentID %>');"></div>
                                            <div>
                                            <a href="<%=this.Url.Content("~/Home/GetOriginalPicture?id="+item.AttachmentID) %>" target="_blank">
                                                <%=Html.AttatchmentImg(item)%>
                                            </a>
                                            </div>
                                        </div>
                                        <%
                        }
                    }
                    else
                    {
                        %>
                        未上传任何站点照片。
                        <%
                    }
                }
               
                        %>
            <div class="clear"></div>
        </div>       
        <div id="dv_photo_upload" class="dv_photo_upload">
                    文件：<input id="file" name="fileName" type="file"  />&nbsp;
                    备注名称：<input id="attatchName" name="attatchName" type="text" maxlength="30" />&nbsp;
                    <input id="Submit1" type="submit" value="上传" onclick="return CheckFileExt()" />
                    
        </div>      
        <%--</iframe>--%>
    </div>
    <%} %>
</body>
<script type="text/javascript" language="javascript">
    // 全局根路径
    var appRootPath = '<%=this.Url.Content("~/") %>';

    //验证上传图片格式
    function CheckFileExt() {
        //得到上传文件的值
        //var fileName = $("#fileName").val(); //document.getElementById("FileUpLoad1").value;
        var fileName = document.getElementById("file").value;

        if (fileName == "" || fileName == null) {
            alert("请选择上传图片！");
            return false;
        }
        if ($("#attatchName").val() == '') {
            alert("备注名称不能为空！");
            return false;
        }
        //返回String对象中子字符串最后出现的位置.   
        var seat = fileName.lastIndexOf(".");
        //返回位于String对象中指定位置的子字符串并转换为小写.   
        var extension = fileName.substring(seat).toLowerCase();
        var allowed = [".jpg", ".gif", ".png", ".bmp", ".jpeg"];

        for (var i = 0; i < allowed.length; i++) {
            if (!(allowed[i] != extension)) {
                return true;
            }
        }
        alert("不支持" + extension + "格式!");
        return false;
    }
   
    $(function() {
        $("#file").change(function() {
            var filePath = $("#file").val();
            var seat = filePath.lastIndexOf("\\");
            var attatchName = filePath.substring(seat + 1, filePath.length);
            $("#attatchName").val(attatchName);
        });
    });
    function delImg(gid) {
        if (!confirm("是否删除该附件？")) {return;}
        var path = appRootPath + "Route/RemoveAttatchment";
        $.ajax({
            type: "POST",
            url: path,
            data: { "id": gid },
            success: function(msg) {
                window.location = '<%=this.Url.Content("~/Route/ViewPhoto?StationID="+ViewData["stationID"]) %>';
            }
        });
    }
    </script>
</html>
